package 
{
	import flash.display.Sprite;
	import flash.events.*;
	import flash.net.Socket;
	import com.demonsters.debugger.MonsterDebugger;
	import com.adobe.serialization.json.JSON;
	import flash.utils.*;
	
	public class Main extends Sprite 
	{
		private var s:Socket;

		public function Main():void 
		{
			if (stage) init();
			else addEventListener(Event.ADDED_TO_STAGE, init);
		}

		private function init(e:Event = null):void 
		{
			MonsterDebugger.initialize(this);
            MonsterDebugger.trace(this, "Hello World!");
			removeEventListener(Event.ADDED_TO_STAGE, init);
			s = new Socket("172.25.200.53", 8888);
			s.addEventListener(ProgressEvent.SOCKET_DATA, sData);
			s.addEventListener(Event.CONNECT, connection);
			s.addEventListener(Event.CLOSE, close);
		}
		
		private function sData(event:ProgressEvent):void
		{
			MonsterDebugger.trace(event, "got data");
			MonsterDebugger.trace(this,  event);
			var ba:ByteArray = new ByteArray();
			s.readBytes(ba);
			MonsterDebugger.trace(ba, ba);
			var header:int = ba.readByte();
			MonsterDebugger.trace(this, header, "header");
			
			
			
			
			var header:int = ba.readByte();
			MonsterDebugger.trace(this, header, "");
			var header:int = ba.readByte();
			MonsterDebugger.trace(this, header, "");
			var header:int = ba.readByte();
			MonsterDebugger.trace(this, header, "");
			var header:int = ba.readByte();
			MonsterDebugger.trace(this, header, "");
			var header:int = ba.readByte();
			MonsterDebugger.trace(this, header, "");
			var header:int = ba.readByte();
			MonsterDebugger.trace(this, header, "");
			var header:int = ba.readByte();
			MonsterDebugger.trace(this, header, "");
			var header:int = ba.readByte();
			MonsterDebugger.trace(this, header, "");
			var header:int = ba.readByte();
			MonsterDebugger.trace(this, header, "");
			var header:int = ba.readByte();
			MonsterDebugger.trace(this, header, "");
			var header:int = ba.readByte();
			MonsterDebugger.trace(this, header, "");
			var header:int = ba.readByte();
			MonsterDebugger.trace(this, header, "");
			var header:int = ba.readByte();
			MonsterDebugger.trace(this, header, "");
			var header:int = ba.readByte();
			MonsterDebugger.trace(this, header, "");
			var header:int = ba.readByte();
			MonsterDebugger.trace(this, header, "");
			
			
			
			
			/*var o:Object = s.readObject();
			MonsterDebugger.trace(event, "UTF BYTES: " + o);
			MonsterDebugger.trace(event, "UTF BYTES2: " + o as Animal);*/
			//s.flush();
		}
		
		private function connection(event:Event):void
		{
			MonsterDebugger.trace(this, "connected");
		}
		
		private function close(event:Event):void
		{
			MonsterDebugger.trace(this, "closed");
		}

	}

}